package cn.edu.wynu.apis.collections.generics;

import cn.edu.wynu.apis.collections.app.Student;

import java.util.HashMap;

public class MapGenerics {
    public static void main(String[] args) {
        // 创建HashMap
        HashMap<String, Integer> map = new HashMap<>();
        // 添加元素使用put方法
        map.put("张三", 90);

        Integer val = map.get("张三");
        for (String key : map.keySet()) {
            System.out.println(key + "的成绩为: " + map.get(key));
        }

        // 泛型的作用:1.编译时检查类型 2.获取时无需强制类型转换
        HashMap<String, Student> stringStudentHashMap = new HashMap<>();
        stringStudentHashMap.put("张三", new Student("111", "张三", 18, "2班", 90));
    }
}
